package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.os.service.SelectSuqiuServiceS;
import com.os.serviceimpl.SelectSuqiuServiceImplS;

import net.sf.json.JSONObject;

public class AddSuqiuControllerS extends HttpServlet{
	SelectSuqiuServiceS ss = new SelectSuqiuServiceImplS();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		int did = Integer.parseInt(req.getParameter("did"));
		int oid = Integer.parseInt(req.getParameter("oid"));
		String fname = req.getParameter("fname");
		int fid = ss.findFidByFnameS(fname);
		String suqiu = req.getParameter("rcontent");
		int rcontent = 0;
		if(suqiu.equals("退菜")){
			rcontent = -1;
		}else if(suqiu.equals("换菜")){
			rcontent = 0;
		}
		String dname = req.getParameter("dname");
		int r_rid = ss.findDidByDnameS(dname);
		String jname = req.getParameter("jname");
		int uid = ss.findJidByJnameS(jname);
		boolean flag = ss.addSuqiusS(did, oid, fid, rcontent, r_rid, uid);
		System.out.println(flag);
		PrintWriter pw = resp.getWriter();
		JSONObject j = new JSONObject();
		j.put("flag", flag);
		pw.write(j.toString());
		System.out.println(j);
		 
	}
}
